package com.demo.starter.web;

import com.demo.starter.service.IQuartzService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@Log4j2
public class JobController {

    @Autowired
    @Qualifier("quartzService")
    private IQuartzService quartzService;

    @RequestMapping("/job/trigger/{groupName}/{jobName}")
    public ResponseEntity<String> trigger(
            @PathVariable(name = "groupName") String groupName,
            @PathVariable(name = "jobName") String jobName) {
        quartzService.trigger(jobName, groupName);
        log.debug("trigger 定时任务 = {}.{}", groupName, jobName);
        return new ResponseEntity<>(HttpStatus.OK);
    }

}
